import { WindowPosition } from "@/core/window/window-position"


export class WindowSize {
  //是否可以横向拖拽窗口大小
  readonly resizeHorizontal: boolean

  //是否可以纵向拖拽窗口大小
  readonly resizeVertical: boolean

  //是否可最小化
  readonly minimize: boolean
  //是否可最大化
  readonly maximize: boolean
  //是否可全屏
  readonly fullscreen: boolean
  readonly width: number
  readonly height: number
  readonly minWidth: number
  readonly minHeight: number
  readonly maxWidth: number | undefined
  readonly maxHeight: number | undefined

  constructor(
    resizeHorizontal: boolean,
    resizeVertical: boolean,
    minimize: boolean,
    maximize: boolean,
    fullscreen: boolean,
    width: number,
    height: number,
    minWidth?: number,
    minHeight?: number,
    maxWidth?: number,
    maxHeight?: number
  ) {
    this.resizeHorizontal = resizeHorizontal
    this.resizeVertical = resizeVertical
    this.minimize = minimize
    //如果窗口不可以进行横向和纵向大小变化,则最大化和全屏都不支持
    if (!this.resizeVertical && !this.resizeHorizontal) {
      this.maximize = false
      this.fullscreen = false
    } else if (!this.resizeVertical || !this.resizeHorizontal) {
      //如果窗口仅允许横向和纵向的变化一种，则窗口可以最大化，但是不能全屏
      this.maximize = maximize
      this.fullscreen = false
    } else {
      this.maximize = maximize
      this.fullscreen = fullscreen
    }
    //如果窗口不支持最大化，则不能支持全屏
    if (!this.maximize) {
      this.fullscreen = false
    }
    this.width = width
    this.height = height
    this.minWidth = minWidth || width
    this.minHeight = minHeight || height
    this.maxWidth = maxWidth
    this.maxHeight = maxHeight
  }

  /*
   * 通过尺寸描述创建一个默认的位置
   */
  public toPosition() {
    const lr = (window.innerWidth - this.width) / 2
    const tb = (window.innerHeight - this.height) / 2
    return new WindowPosition(lr, tb, lr, tb)
  }
}
